package com.qf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.pojo.DtsOrder;
import com.qf.vo.CategorySellAmts;
import com.qf.vo.DayStatis;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
public interface DtsOrderMapper extends BaseMapper<DtsOrder> {

    /**
     * 统计最近多少天内的订单增长量和当前订单总金额
     * @return
     */
    @Select("SELECT DATE_FORMAT(a.add_time,\"%Y-%m-%d\") as dayStr ," +
            "count(*) as cnts , sum(actual_price) as amts " +
            "FROM dts_order a " +
            "WHERE a.deleted = 0 " +
            "GROUP BY DATE_FORMAT(a.add_time,\"%Y-%m-%d\") ")
    public List<DayStatis> staticIncresOrderCnt();

    /**
     * 按照商品分类统计订单金额
     * @return
     */
    @Select("SELECT d.`name`, SUM(a.price) as value " +
            "FROM dts_order_goods a  " +
            "LEFT JOIN dts_order b on a.order_id = b.id " +
            "LEFT JOIN dts_goods c on a.goods_id = c.id " +
            "LEFT JOIN dts_category d on c.category_id = d.id " +
            "WHERE a.deleted=0 AND b.deleted=0 and d.`name` is NOT NULL " +
            "GROUP BY d.`name` ")
    public List<CategorySellAmts> categorySell();
}
